<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="/res/include/base-head.jsp"%>
	<%@include file="/res/include/jquery-easyui.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/ad/adBase.js"></script>
  </head>
  <body>
<form id="data-form">
	<div class="form_item">
		<dl>
			<dt>ID：</dt>
			<dd>
				<input type="hidden" name="id" value="${adBaseVo.id}"/>
				${adBaseVo.id}
			</dd>
		</dl>
		<dl>
			<dt>选择广告位置：</dt>
			<dd>
				<select name="type">
					<c:forEach items="${list}" var="item">
						<option value="${item.code}" <c:if test="${adBaseVo.type==item.code}">selected="selected"</c:if>>${item.name}</option>
					</c:forEach>
				</select>
			</dd>
		</dl>
		<dl>
			<dt>社区：</dt>
			<dd>
				<select name="communityId">
					<option value="" <c:if test="${adBaseVo.communityId==null}"> selected="selected"</c:if> >请选择</option>
					<c:forEach items="${cList}" var="item">
						<option value="${item.id}" <c:if test="${adBaseVo.communityId==item.id}"> selected="selected"</c:if>>${item.name}</option>
					</c:forEach>
				</select>
			</dd>
		</dl>
		<dl>
			<dt>排序：</dt>
			<dd>
			<input  type="text"  name="oidx" value="${item.oidx}"/> 
			</dd>
		</dl>
		<dl>
			<dt>广告图片：</dt>
			<dd>
				<ul class="product_imglist img_imglist">
					<c:choose>
			        	<c:when test="${!empty adBaseVo && !empty adBaseVo.img}">
							<li><a href="javascript:;" class="item" id="pic0" type="img" onclick="admin.adBase.addImg('pic0')">
							<p class="img"><img src="http://file.xfquanquan.com${adBaseVo.img}" alt="" /></p>
							</a>
							</li>
						</c:when>
		        		<c:otherwise>
		        			<li><a href="javascript:;" class="item" id="pic0" type="img" onclick="admin.adBase.addImg('pic0')">添加图片</a>
		        			</li>
		        	    </c:otherwise>
	        	</c:choose>	
				</ul>
			</dd>
		</dl>
		<dl>
			<dt>标题：</dt>
			<dd>
			<input  type="text"  name="title" value="${adBaseVo.title}"/> 
			</dd>
		</dl>
		<dl>
			<dt>标题图片：</dt>
			<dd>
				<ul class="product_imglist img_imglist">
				<c:choose>
			        <c:when test="${!empty adBaseVo && !empty adBaseVo.titleImg}">
						<li><a href="javascript:;" class="item" id="titlePic0" type="title" onclick="admin.adBase.addImg('titlePic0')">
						<p class="img"><img src="http://file.xfquanquan.com${adBaseVo.titleImg}" alt="" /></p>
						</a>
						</li>
					</c:when>
		        	<c:otherwise>
	        			<li>
	        				<a href="javascript:;" class="item" id="titlePic0" type="title" onclick="admin.adBase.addImg('titlePic0')">添加图片</a>
	        			</li>
		        	</c:otherwise>
	        	</c:choose>	
				</ul>
			</dd>
		</dl>
		<dl>
			<dt>广告超链接地址：</dt>
			<dd>
			<input  type="text"  name="href" value="${adBaseVo.href}"/> 
			</dd>
		</dl>
		<dl>
			<dt>UI参数：</dt>
			<dd>
				 <select id="jsonData" name="jsonData"  style="padding: 5px;" >
					<option value="" <c:if test="${adBaseVo.jsonData==null}"> selected="selected" </c:if> >请选择店铺</option>
					<c:forEach items="${mallShopVos}" var="item">
						<option value="${item.id}"  <c:if test="${adBaseVo.shopId!=null && adBaseVo.shopId==item.id}"> selected="selected"</c:if> >${item.name}</option>
					</c:forEach>
				</select>
			    <!--<input  type="text"  name="jsonData" value="${adBaseVo.jsonData}"/> -->
			</dd>
		</dl>
		
		<dl>
			<dt>UI路径：</dt>
			<dd>
			<input  type="text"  name="path" value="${adBaseVo.path}" readOnly/> 
			</dd>
		</dl>
		<dl>
			<dt>备注：</dt>
			<dd>
			<input  type="text"  name="remark" value="${adBaseVo.remark}"/> 
			</dd>
		</dl>
		<dl>
			<dt>内容：</dt>
			<dd>
				<textarea class="txt grid-75" id="content" name="content" oninput="admin.adBase.netMsgChange('content',360)" onpropertychange="admin.communityNotice.netMsgChange('content',360)" rows="4" >${adBaseVo.content}</textarea>
			</dd>
		</dl>
		<dl>
			<dt>内容图片：</dt>
			<dd>
				<ul class="product_imglist img_imglist">
					<c:forEach items="${listImgs}" begin="0" end="4" varStatus="i" var="item">
						<li><a href="javascript:;" class="item" id="contentImgPic${i.index}" type="content" onclick="admin.adBase.addImg('contentImgPic${i.index}')">
						<p class="img"><img src="http://file.xfquanquan.com${item}" alt="" /></p>
						</a>
						</li>
					</c:forEach>
					<c:forEach begin="${fn:length(listImgs)}" end="4" varStatus="i">
						<li><a href="javascript:;" class="item" id="contentImgPic${i.index}" type="content" onclick="admin.adBase.addImg('contentImgPic${i.index}')">添加图片
						</a>
						</li>
					</c:forEach>
				</ul>
				<em class="p0">上传4:3的JPG/PNG/BMP图片，建议：720*540px</em>
			</dd>
		</dl>
		<p class="page_btn"><input type="button" id="saveBtn" value="保存" class="btn_blue" onclick="doSave();"/></p>
	</div>
</form>
<script type="text/javascript">

function delLogoImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="img" onclick="admin.adBase.addImg(\'img\')">添加图片</a>');
}

function doSave() {
	var img = "";
	var titleImg = "";
	var contentImg = "";
	var imglist = $(".img_imglist img");
	if (imglist && imglist.length > 0) {
		imglist.each(function() {
			var parent=$(this).parent().parent();
			if(parent.attr("type")=="img"){
				if (img == "") {
					img += $(this).attr("src").replace(imgFilePath, "");
				} else {
					img += ";" + $(this).attr("src").replace(imgFilePath, "");
				}
			}else if(parent.attr("type")=="title"){
				if (titleImg == "") {
					titleImg += $(this).attr("src").replace(imgFilePath, "");
				} else {
					titleImg += ";" + $(this).attr("src").replace(imgFilePath, "");
				}
			}else if(parent.attr("type")=="content"){
				if (contentImg == "") {
					contentImg += $(this).attr("src").replace(imgFilePath, "");
				} else {
					contentImg += ";" + $(this).attr("src").replace(imgFilePath, "");
				}
			}
		});
	} else {
		top.showInfo('请上传产品图片');
		return;
	}
	var url = contextPath + '/ad/base/update';
	if (!$('#data-form').form('validate'))
		return;
	var data = $('#data-form').form('jsonObject');
	if(data.jsonData!="")
	   data.jsonData = "{\"shopId\":\""+data.jsonData+"\"}";
    else
		data.path = '';
	data.img = img;
	data.titleImg = titleImg;
	data.contentImg = contentImg;
	$.post(url, data, function(result) {
		if (result.code == 1) {
			top.showInfo('保存成功');
			top.addTab("",'广告记录', contextPath+'/ad/base/list');
		} else {
			top.showInfo('保存失败:' + result.msg);
		}
	}, 'json');
}

</script>
</body>
</html>
